
$().ready(function() {
    $("#form-addtask").validate({
        rules: {
          plan_department: "required",
          plan_subject:"required",
          plan_way:"required",
          total_step: {
            digits:true,
            required: true
          },
          plan_num: {
            required: true,
            number: true
          },
        },
        messages: {
          plan_department: "请选择业务部门",
          plan_subject: "请输入工作科目",
          plan_way: "请输入具体方法",
          total_step: {
            required: "请输入总步骤",
            digits: "请输入整数"
          },
          plan_num: {
            required: "请输入分数",
            number: "请输入数字格式"
          },
        }
    });
});

init()
function init(){
    var ajaxData={
        url:'base_manage/orglistapi',
        fromwho:'manage',
    }
    getAjaxSyn(ajaxData,function(data){
        if(data.code==200){
            var curPageData=data.data
            var tplData={curData:curPageData}
            var html= template('tpl-orgOption', tplData);
            $('#select-department').append(html)
        }
    })
}
$('.save').on('click',function(){
    $("#form-addtask").submit()
})
$.validator.setDefaults({
    submitHandler: function() {
        upData()
    },
    showErrors: function(errorMap,errorList) { 
        try{
        	mui.toast(errorList[0]['message'])
        }catch(e){
        	return 
        }
    },
    onclick:false,
    onfocusout:false,
    onkeyup:false
});
function upData(){
    var index
    var sendData=$("#form-addtask").serialize()
    var ajaxData={
        url:'Task_Manage/addeditTask',
        fromwho:'manage',
        sendData:sendData
    }
    upAjax(ajaxData,function(data){
        if(data.code==200){
            layer.open({
                content: '提交成功'
                ,skin: 'msg'
                ,time: 1//2秒后自动关闭
            });
            setTimeout(function(){
                mui.init({
                    beforeback: function(){
                        mui.plusReady(function(){   
                            var fa = plus.webview.currentWebview().opener()
                            mui.fire(fa, 'pagereload');  
                        })
                    }
                });
                mui.back()
            },1000)
        }else{
            layer.open({
                content: '提交失败'
                ,skin: 'msg'
                ,time: 1//2秒后自动关闭
            });
        }
    },function(){index=layer.open({type: 2,content: '提交中'});},function(){layer.close(index);})
}
